/**
 * Copyright (c) 2013 Mark Tielemans
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * DISCLAIMER
 * This software is provided "as is" and any expressed or implied warranties, including, but not limited to, the implied warranties of 
 * merchantability and fitness for a particular purpose are disclaimed. In no event shall the regents or contributors be liable for any 
 * direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute 
 * goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in 
 * contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if 
 * advised of the possibility of such damage.
 */
package nl.marktielemans.easydb.model;

/**
 * Represents a column in a database table, of data type <code>T</code>.
 * 
 * @author Mark Tielemans
 * @since 1.0
 * @version 1.0
 * @param <T> the data type for this table column
 */
public class TableColumn<T> {

	private T value;
	
	private boolean nullable;
	private String propertyName;
	private boolean isAutoIncrement;
	private int length = 0;
	private DataType type;
	private IndexType indexType;
	
	/**
	 * Define a new table column.
	 * 
	 * @param propertyName as in the database
	 * @param nullable
	 * @param autoIncrement
	 * @param type
	 * @param indexType
	 */
	public TableColumn(String propertyName, boolean nullable,
			boolean autoIncrement, DataType type, IndexType indexType) {
		super();
		this.nullable = nullable;
		this.propertyName = propertyName;
		this.isAutoIncrement = autoIncrement;
		this.type = type;
		this.indexType = indexType;
	}
	
	/**
	 * Defines a new table column.
	 * 
	 * @param propertyName as in the database
	 * @param nullable
	 * @param autoIncrement
	 * @param type
	 * @param length
	 * @param indexType
	 */
	public TableColumn(String propertyName, boolean nullable,
			boolean autoIncrement, DataType type, int length, IndexType indexType) {
		this(propertyName, nullable, autoIncrement, type, indexType);
		this.length = length;
	}
	
	/**
	 * Create a table column representation with a property value.
	 * 
	 * @param propertyName as in the database
	 * @param value for a single row
	 * @see EasyDBEntity#getProperties()
	 */
	public TableColumn(String propertyName, T value) {
		this.propertyName = propertyName;
		this.value = value;
	}
	
	public boolean getIsNullable() {
		return nullable;
	}

	public void setIsNullable(boolean nullable) {
		this.nullable = nullable;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public boolean getIsAutoIncrement() {
		return isAutoIncrement;
	}

	public void setIsAutoIncrement(boolean autoIncrement) {
		this.isAutoIncrement = autoIncrement;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public DataType getType() {
		return type;
	}

	public void setType(DataType type) {
		this.type = type;
	}
	
	public IndexType getIndexType() {
		return indexType;
	}

	public void setIndexType(IndexType indexType) {
		this.indexType = indexType;
	}

	public T getValue() {
		return value;
	}

	public void setValue(T value) {
		this.value = value;
	}
	
	/**
	 * Returns the property name of this column.
	 * @return same as {@link #getPropertyName()}
	 */
	@Override
	public String toString() {
		return this.getPropertyName();
	}
}
